#!/bin/sh
#
# Startup script for the Common Console Framework
# This is intended to be run from inittab with a "once" entry.

START_TRACE="FALSE"
#START_TRACE="TRUE"

export PATH=/opt/IBMJava/jre/bin:$PATH
#
export LD_LIBRARY_PATH=/opt/hsc/lib:$LD_LIBRARY_PATH
# The following two exports are required for tasklets-on-pHMC:
export JITC_COMPILEOPT=NINLINING{java/math/BigInteger}{oddModPow}
hscnls=`echo /opt/hsc/jars/i18n/hsc_*.jar | sed -e 's/ /:/g'`
export CLASSPATH=$CLASSPATH:/usr/websm/codebase/pluginjars/hmcdebug.jar:/usr/websm/codebase/pluginjars/hsc.jar:$hscnls:/usr/websm/codebase/wsm.jar:/usr/websm/codebase/pluginjars/rmcjava.jar:/usr/websm/codebase/pluginjars/aca.jar:/usr/websm/codebase/pluginjars/hsc_bundles.jar:/usr/websm/codebase/pluginjars/bundles.jar:/opt/ccfw/ccfw.jar:/usr/websm/codebase/pluginjars/sniacimom.jar
#
# Suppress listening on the JDI debugging port
# 8/4/04 - For performance reasons, disable the port for now
export HMC_DEBUG_OFF=1 
#
# Allow the CCFW Manager to connect to the CIM Server if started in SSL mode.
export HMC_JVM_EXTRA_OPTS="-Djavax.net.ssl.keyStore=/usr/websm/codebase/SM.pubkr -Djavax.net.ssl.keyStorePassword=defp -Dorg.snia.wbem.cimom.properties=/opt/hsc/data/cim.properties"
#

# Initialize some miscellaneous variables.
TOP_DIR='/opt/ccfw'
OUT_FILE="$TOP_DIR/ccfw.out"
TRACE_CWD_PGM='iqzdtcre'
TRACE_DDFC_PGM='iqzdtcon'
. $TOP_DIR/hmcfunctions
TRACE_DDFC_FILE="$(queryFileLocation iqzdtrac.trm)iqzdtrac.trm"
TRACE_MASKS_FILE='/console/data/iqzdtctl.trm'

# Remove the TowersStarted file since we will be starting CCFW to recreate it.
rm -f $TOP_DIR/TowersStarted > /dev/null 2>&1

# Reset the CCFW output collection file.
echo '' > $OUT_FILE

# If requested, start tracing to file if not already being performed. Any existing trace file will be copied first 
# if tracing to file is started here.
if [ $START_TRACE == "TRUE" ]; then
    # See if trace is already running.
    creLines=$(pstree -lp|grep $TRACE_CWD_PGM)
    if [ -z "$creLines" ]; then
       echo "No $TRACE_CWD_PGM program(s) running." >> $OUT_FILE
       conLines=$(pstree -lp|grep $TRACE_DDFC_PGM)
       if [ -z "$conLines" ]; then
          echo "No $TRACE_CWD_PGM or $TRACE_DDFC_PGM program(s) running." >> $OUT_FILE

          # Move the trace file if one already exists.
          if [ -e $TRACE_DDFC_FILE ]; then
             #newFile="$TRACE_DDFC_FILE.$(date --iso-8601='seconds')"
             newFile="$TRACE_DDFC_FILE.previous"
             echo 'moved trace file '$TRACE_DDFC_FILE' to '$newFile >> $OUT_FILE
             mv -f $TRACE_DDFC_FILE $newFile 
          fi

          # Start tracing for all masks and T,F,D,L level traces.
          echo '*      TFDL' > $TRACE_MASKS_FILE
          /usr/bin/$TRACE_DDFC_PGM -s90000 -p >> $OUT_FILE 2>&1 &
          echo "started $TRACE_DDFC_PGM" >> $OUT_FILE
       else
          echo "$TRACE_DDFC_PGM program(s) already running." >> $OUT_FILE
       fi
    else
       echo "$TRACE_CWD_PGM program(s) already running." >> $OUT_FILE
    fi
fi

# Start the CCFW Manager.
$TOP_DIR/runccfw $TOP_DIR ccfw >> $OUT_FILE 2>&1 &

